package org.jslaughter.component.action;

import org.nvframe.component.AbstractComponent;
import org.nvframe.entity.Entity;
import org.nvframe.event.EventService;
import org.nvframe.event.eventtype.UpdateEvent;
import org.nvframe.event.eventtype.UpdateListener;
import org.nvframe.exception.NVFrameException;
import org.nvframe.exception.NVFrameRuntimeException;
import org.nvframe.util.settings.SettingsObj;

/**
 * 
 * @author Nik Van Looy
 */
public class ShootAction extends AbstractComponent implements UpdateListener {
	
	protected String bulletId;
	protected int reloadTimeMs;
	protected int currReloadTimeMs;
	protected int shotDelayMs;
	protected int magazineCap;
	
	protected String reloadSound;
	protected String shotSound;
	
	protected int remainingCap;
	protected int shotTimerMs;
	protected boolean reloading;
	
	public ShootAction(String id, Entity owner, SettingsObj settings) throws NVFrameException {
		super(id, owner);
		
		bulletId = settings.getString("bulletEntityId", null);
		reloadTimeMs = settings.getInt("reloadTimeMs", 2000);
		shotDelayMs = settings.getInt("shotDelayMs", 1000);		
		magazineCap = settings.getInt("magazineCap", 22);
		shotDelayMs = settings.getInt("shotDelayMs", 800);
		
		reloadSound = settings.getString("reloadSound", null);
		shotSound = settings.getString("shotSound", null);
		
		// reload gun to full cap
		remainingCap = magazineCap;
		reloading = false;
		shotTimerMs = shotDelayMs;
		
		currReloadTimeMs = 0;
		
		EventService.getInstance().addEventListener(this);
	}

	@Override
	public void onUpdate(UpdateEvent event) {
		throw new NVFrameRuntimeException("you must override ShootAction:onUpdate method");
	}

}
